﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace ConsoleApplication1
{
    class MD5Util
    {
        public static string GetMD5(string data, String charset)
        {
            //MD5加密，同样的字符串在每次加密后的字符串是一样的
            byte[] bData = Encoding.GetEncoding(charset).GetBytes(data);
            MD5CryptoServiceProvider myMD5 = new MD5CryptoServiceProvider();
            bData = myMD5.ComputeHash(bData);
            StringBuilder sBuilder = new StringBuilder();
            for (int i = 0; i < bData.Length; i++)
            {
                //十六进制转成小写的英文字符
                sBuilder.Append(bData[i].ToString("x2"));
            }
            return sBuilder.ToString();
        }
    }
}
